<?php

class verifyRegister extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('register_Model');
	}

	function index() {
		$this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean|is_unique[customer.login]');
		$this->form_validation->set_rules('first', 'First', 'trim|required|xss_clean');
		$this->form_validation->set_rules('last', 'Last', 'trim|required|xss_clean');
		$this->form_validation->set_rules('email', 'Email', 'required|xss_clean|valid_email|is_unique[customer.email]');
		$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]');
		$this->form_validation->set_rules('password_conf', 'Password Confirmation', 'trim|required|xss_clean|matches[password]');

		if ($this->form_validation->run() == true) {
			$data = array(
						'login' => $this->input->post('login'),
						'first' => $this->input->post('first'),
						'last' => $this->input->post('last'),
						'email' => $this->input->post('email'),
						'password' => $this->input->post('password'));
		}
		if ($this->form_validation->run() == true && $this->register_Model->register($data)) {
			$this->session->set_flashdata('registration_message', 'Thank you for registering. Please log in!');
			redirect('login');
		}
		else {
			$this->load->view('register');
		}
	}
}